package com.mobilebsc.httpclient.callback;

import java.util.List;

import android.util.Log;

import com.loopj.android.http.RequestParams;
import com.mobilebsc.datatype.StrategicGoal;
import com.mobilebsc.exception.NotImplementedException;

public class StrategicGoalRestClientUsage implements IRestClientUsage<StrategicGoal>, IAsyncTaskCompleteListener<List<StrategicGoal>>{

	private static final String TAG = "PerspectiveRestClientUsage";
	private IAsyncTaskCompleteListener<List<StrategicGoal>> callback;
	private String svcUrl;
	
	public StrategicGoalRestClientUsage(IAsyncTaskCompleteListener<List<StrategicGoal>> callback) {
		this.callback = callback;
		this.svcUrl = "goals";
	}
	
	@Override
	public void getAll() {
		StrategicGoalHttpResponseHandler httpResponseHandler = new StrategicGoalHttpResponseHandler(this);
		MbscRestClient.get(svcUrl, null, httpResponseHandler);
	}
	
	@Override
	public void getById(int strategicGoalId) {
		StrategicGoalHttpResponseHandler httpResponseHandler = new StrategicGoalHttpResponseHandler(this);
		MbscRestClient.get(svcUrl, new RequestParams("id", strategicGoalId), httpResponseHandler);
	}
	
	@Override
	public void add(StrategicGoal element) {
		throw new NotImplementedException();		
	}

	@Override
	public void delete(StrategicGoal element) {
		throw new NotImplementedException();		
	}
	
	public void getByPerspectiveId(int perspectiveId) {
		StrategicGoalHttpResponseHandler httpResponseHandler = new StrategicGoalHttpResponseHandler(this);
		MbscRestClient.get(svcUrl + "/perspective", new RequestParams("id", perspectiveId), httpResponseHandler);
	}
	
	public void getReferencedStrategicGoals(int strategicGoalId) {
		StrategicGoalReferencedByX_HttpResponseHandler httpResponseHandler = new StrategicGoalReferencedByX_HttpResponseHandler(this);
		MbscRestClient.get(svcUrl + "/referencedBy", new RequestParams("id", strategicGoalId), httpResponseHandler);
	}
	
	@Override
	public void onTaskComplete(List<StrategicGoal> result) {
		Log.i(TAG,"result[0].content: " + result.get(0).getId() + ", " + result.get(0).getName() + ", " + result.get(0).getDescription());
		
		callback.onTaskComplete(result);
	}
}